package com.bjsxt.service.impl;

import com.bjsxt.service.feign.OrderServiceFeign;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class OrderServiceApi {
    
    private static Logger logger = LoggerFactory.getLogger(OrderServiceApi.class) ;
    
//    @Autowired
//    private RestTemplate restTemplate ;

    @Autowired
    private OrderServiceFeign orderServiceFeign ;

    public void create(String userId ,String productNo ,int count){
//        ResponseEntity<Void> responseEntity = restTemplate.getForEntity(
//                "http://order-service/create/{userId}/{productNo}/{count}",
//                Void.class,
//                userId,
//                productNo,
//                count
//        );
        ResponseEntity<Void> responseEntity = orderServiceFeign.create(userId, productNo, count);
        if(responseEntity.getStatusCode()== HttpStatus.OK){
            logger.info("远程调用订单服务成功");
            return;
        }
        throw new RuntimeException("远程调用订单服务失败") ;
    }
    
}
